home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11193 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ix.netcom.com!news
  2. From: jdmorris@ix.netcom.com (Jason D. Morris)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Exception: GPF and DIV by 0 ?
  5. Date: Wed, 13 Mar 1996 04:37:24 GMT
  6. Organization: Netcom
  7. Message-ID: <31465068.7122141@nntp.ix.netcom.com>
  8. References: <3145D33E.208A@ios.chalmers.se>
  9. NNTP-Posting-Host: pon-mi1-21.ix.netcom.com
  10. X-NETCOM-Date: Tue Mar 12 10:36:21 PM CST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. On Tue, 12 Mar 1996 19:40:46 +0000, Michael Sch=?iso-8859-1?Q?=F6n
  14. <ei39418@ios.chalmers.se>?= wrote:
  15.  
  16. >Hello,
  17. >
  18. >Does anyone know how to catch the following exceptions in Borland C++ =
  19. >
  20. >4.52:
  21. >- General Protection Fault (GPF)
  22. >- Division by zero
  23. >
  24. >I would like to provide an error handler for these errors.
  25. >
  26. >#Solution 1 - does not work:
  27. >The following code 'should' catch it:
  28. >
  29. >try
  30. >{
  31. >    // some C++ code - generates the above mentioned exceptions.
  32. >}
  33. >catch(...)
  34. >{
  35. >    // This catch ALL statement does not catch the exceptions.
  36. >    // Instead Windows report them.
  37. >}
  38. >#Solution 2 - does not work either:
  39. >// Connect an error handler function via the set_unexpected macro.
  40. >set_unexpected( My_Own_Error_Handler() )
  41. >
  42. >
  43. >Any ideas?
  44. >One solution for the division fault is to put an error handler on the DIV =
  45. >
  46. >interrupt, but that is not a good solution. There must be a better one.
  47. >
  48. >How do one catch a GPF exception?
  49.  
  50. The exceptions you mention are *hardware* exceptions.  C++ is designed
  51. to handle *software* exceptions.  To trap hardware exceptions you one
  52. ANSI standard option, use a signal handler.  If you are working on
  53. Win95 or NT you can use structured exception handling.  In both cases,
  54. you're better off programming defensively to avoid such exceptions in
  55. the first place, rather than letting them happen and then trying to
  56. correct them.
  57.  
  58. Jason
  59.  
  60.